<?php
/**
 * Created by PhpStorm.
 * User: baiguiren
 * Date: 3/26/17
 * Time: 8:49 AM
 */

namespace App\Http\Controllers\Other;

use DB;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;

class MailController extends Controller
{
    public function getAll()
    {
        $filter = Input::get('filter', 2);

        $builder = DB::table('account');
        if ($filter == 1) {
            $builder->where('has_ssr', 1);
        }
        if ($filter == 2) {
            $builder->where('used', 0);
        }
        $clone_builder = clone $builder;
        $count = $clone_builder->count();
        $account_arr = $builder->get();

        return view('mail.mail')
            ->with('filter', $filter)
            ->with('count', $count)
            ->with('mails', $account_arr);
    }

    public function updateToUsed()
    {
        $id = Input::get('id');
        DB::table('account')->where('id', $id)->update(['used'=>1]);
    }

    public function markSSR()
    {
        $id = Input::get('id');
        DB::table('account')->where('id', $id)->update(['has_ssr'=>1]);
    }
}